<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称">
              <j-input placeholder="请输入项目名称" v-model="queryParam.projectName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <!-- <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <a @click="assign(record)">分配项目</a>
        </span>
      </a-table>
    </div>
  </a-card>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { api } from '../DpTScopeDataService.js'
export default {
  name: 'DpTScopeDataForm',
  mixins: [JeecgListMixin, mixinDevice],
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      disableMixinCreated: true,
      // 表头
      columns: [
        {
          title: '项目编码',
          align: 'center',
          dataIndex: 'projectId'
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'projectName'
        },
        {
          title: 'oms项目编码',
          align: 'center',
          dataIndex: 'sourceId'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {
        dataId: [{ required: true, message: '请输入自增编号!' }]
      },
      url: {
        list: '/datapipeline/biz/dpTProjects',
        add: api.add,
        edit: api.add,
        queryById: api.queryById
      },
      queryParam: {}
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    assign(record) {
      let httpurl = this.url.add
      var method = 'post'
      var model = {}
      model.appKey = this.queryParam.appKey
      model.projectValue = record.projectId
      const that = this
      httpAction(httpurl, model, method)
        .then(res => {
          if (res.success) {
            that.$message.success(res.message)
            that.searchQuery()
            that.$emit('ok')
          } else {
            that.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.confirmLoading = false
        })
    },
    add(queryParam) {
      this.queryParam = queryParam
      this.loadData()
      this.visible = true
    }
  }
}
</script>

